package xyf.p04.tree;

import java.util.List;

/**
 * ClassName: P0559_NMaxDepth
 * Description:
 * Author: xyf
 * Date: 9/7/22 8:42 PM
 * Version: 1.0
 **/
public class P0559_NMaxDepth
{
    class Node
    {
        public int val;
        public List<Node> children;

        public Node()
        {
        }

        public Node(int _val)
        {
            val = _val;
        }

        public Node(int _val, List<Node> _children)
        {
            val = _val;
            children = _children;
        }
    }

    public int maxDepth(Node root)
    {
        if (root == null)
        {
            return 0;
        }
        List<Node> children = root.children;
        int max = 0;
        for (Node child : children)
        {
            int depth = maxDepth(child);
            max = Integer.max(depth, max);
        }
        return max + 1;
    }


}
